package org.jackysoft.ztree;

import org.jackysoft.entity.Department;

public class DepartmentZtreeFunction extends
		AbstractZTreeFunction<Department> {

	private boolean simple = false;

	public DepartmentZtreeFunction() {
		super();

	}

	public DepartmentZtreeFunction(boolean simple) {
		super();
		this.simple = simple;
	}

	@Override
	public ZTreeNode apply(Department from) {
		if (simple)
			return new ZTreeNode(from.getId(), from.getName());
		ZTreeNode zn = new ZTreeNode();
		zn.setId(from.getId() + "");
		zn.setName(from.getName());
		zn.setIsParent("true");
		zn.setChecked(false);
		zn.setOpen(false);
		zn.setNocheck(false);
		zn.setSort(from.getSort());
		zn.setZtype("department");
		if (from.getParent() != null)
			zn.attr("parentId", from.getParent());
		else
			zn.attr("parentId", null);
		return zn;
	}

}
